/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-07
 * Time: 13:55
 */
public class Demo14 {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 3; i++) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("thread线程结束");
        },"t");
        t.start();
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("main线程: " + Thread.currentThread().getState());
        System.out.println("t线程: " + t.getState());
        try {
            System.out.println("main线程: " + Thread.currentThread().getState());
            System.out.println("t线程: " + t.getState());
            t.join();//让main线程等待t线程先结束，在这个过程中main线程会一直处于阻塞等待
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main线程: " + Thread.currentThread().getState());
        System.out.println("t线程: " + t.getState());
        System.out.println("main线程结束");
    }
}
